package com.iot.common.utils;

import java.util.Random;

/**
 * @author Cao.ning
 * @date 2022/12/30
 */
public class RandomUtil {

    private static final String charts = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";

    public static String genCaptchaNumber(int digit){
        Random random = new Random();
        StringBuilder str = new StringBuilder("");
        for(int i= 0; i< digit; i++){
            str.append(charts.charAt(random.nextInt(10)));
        }
        return str.toString();
    }

    public static String genCaptchaChar(int digit){
        Random random = new Random();
        StringBuilder str = new StringBuilder("");
        for(int i= 0; i< digit; i++){
            str.append(charts.charAt(random.nextInt(52) + 10));
        }
        return str.toString();
    }

    public static String genCaptcha(int digit){
        Random random = new Random();
        StringBuilder str = new StringBuilder("");
        for(int i= 0; i< digit; i++){
            str.append(charts.charAt(random.nextInt(62)));
        }
        return str.toString();
    }

    public static void main(String[] args) {
        System.out.println(genCaptchaNumber(6));
        System.out.println(genCaptchaNumber(6));
        System.out.println(genCaptchaNumber(6));
        System.out.println(genCaptchaNumber(6));
    }
}
